# Copyright 2023 Specter Ops, Inc.
#
# Licensed under the Apache License, Version 2.0
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0

apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ .Values.graphdb.name }}
  namespace: {{ .Values.namespace }}
spec:
  replicas: {{ .Values.graphdb.replicas }}
  selector:
    matchLabels:
      app: {{ .Values.graphdb.appName }}
  template:
    metadata:
      labels:
        app: {{ .Values.graphdb.appName }}
    spec:
      containers:
      - name: {{ .Values.graphdb.container.name }}
        image: {{ .Values.graphdb.container.image }}
        env:
        - name: NEO4J_AUTH
          value: "{{ .Values.graphdb.container.env.NEO4J_AUTH_USER }}/{{ .Values.graphdb.container.env.NEO4J_AUTH_PASS }}"
        - name: NEO4J_dbms_allow__upgrade
          value: "{{ .Values.graphdb.container.env.NEO4J_dbms_allow__upgrade }}"
        ports:
        - containerPort: {{ (index .Values.graphdb.container.ports 0).containerPort }}
        - containerPort: {{ (index .Values.graphdb.container.ports 1).containerPort }}
        livenessProbe:
          exec:
            command:
            - wget
            - -O
            - /dev/null
            - -q
            - http://127.0.0.1:{{ (index .Values.graphdb.container.ports 1).containerPort }}
          initialDelaySeconds: {{ .Values.graphdb.livenessProbe.initialDelaySeconds }}
          periodSeconds: {{ .Values.graphdb.livenessProbe.periodSeconds }}
          timeoutSeconds: {{ .Values.graphdb.livenessProbe.timeoutSeconds }}
          failureThreshold: {{ .Values.graphdb.livenessProbe.failureThreshold }}
        {{- if .Values.graphdb.volumes.pvcEnabled }}
        volumeMounts:
        - name: neo4j-data
          mountPath: /var/lib/neo4j/data
        {{- end }}
      {{- if .Values.graphdb.volumes.pvcEnabled }}
      volumes:
      - name: neo4j-data
        persistentVolumeClaim:
          claimName: {{ .Values.graphdb.volumes.persistentVolumeClaim.claimName }}
      {{- end }}
